package nina.yiyou.performance.s10init.start

import nina.yiyou.performance.s10init.output.PerformFillGenerator
import nina.yiyou.performance.s20confirm.input.BasicExcelReaderV2
import nina.yiyou.salary.input.InfoExcelCollector
import nina.yiyou.salary.input.config.ConfigExcelReader
import nina.yiyou.salary.output.ResultMapMaker
import nina.yiyou.salary.output.util.OutputPathResolver

import java.nio.file.Path
import java.nio.file.Paths

class PerformStep1Runner {

  PerformStep1Runner(Path workshopPath) {
    _workshopPath = workshopPath
  }

  void run() {
    Map globalMap = ConfigExcelReader.create(_workshopPath).read().global()
    def (Map basicMap) = new InfoExcelCollector([
        ['in.花名册', { String p -> new BasicExcelReaderV2(p).read() }],
    ], globalMap, _workshopPath).collect()

    Map computeMap = [:]// new S1ComputeMapMaker(basicMap).make()
    List<Map> employeeResult = new ResultMapMaker([
        ['花名册', basicMap.findAll { !it.value['离职时间'] }],
        ['计算', computeMap],
    ]).make().values().asList()

    Path outDir = new OutputPathResolver(_workshopPath, globalMap, 'out.绩效待填').resolve()
    Path tmpDir = Paths.get(outDir.toString() + '_tmp')

    new PerformFillGenerator(_workshopPath.resolveSibling('internal')
        .resolve('perform_s10init.xlsx'), employeeResult, outDir, tmpDir).generate()
  }

  private final Path _workshopPath
}
